/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package etf.pia.util;

import etf.pia.entity.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Alejandro
 */
public class Initializer {

    public static void initKatedra(List<Predmet> list){
        for(Predmet p: list){
            Hibernate.initialize(p.getKatedra());
        }
    }
    public static void initLab(Predmet p) {
        for (LabVezbe lv :  new ArrayList<LabVezbe>(p.getLabVezbes())) {
            if (!Hibernate.isInitialized(lv.getFajlovis())) {
                Hibernate.initialize(lv.getFajlovis());
            }
        }
    }

    public static void initDomaci(Predmet p) {
        for (Domaci lv :  new ArrayList<Domaci>(p.getDomacis())) {
            if (!Hibernate.isInitialized(lv.getFajlovis())) {
                Hibernate.initialize(lv.getFajlovis());
            }
        }
    }

    public static void initPredmets(Zaposleni z) {
        Hibernate.initialize(z.getPlanAngazovanjas());
        for (PlanAngazovanja p : new ArrayList<PlanAngazovanja>(z.getPlanAngazovanjas())) {
            Hibernate.initialize(p.getPredmet());
        }
    }
    public static void initPredmets(Student z) {
        Hibernate.initialize(z.getRasporeds());
        for (Raspored p : new ArrayList<Raspored>(z.getRasporeds())) {
            Hibernate.initialize(p.getPredmet());
        }
    }

    public static ArrayList<Predmet> toList(Zaposleni z) {
        if (z == null) {
            return null;
        }
        ArrayList<Predmet> list = new ArrayList<Predmet>();
        for (PlanAngazovanja p : new ArrayList<PlanAngazovanja>(z.getPlanAngazovanjas())) {
            list.add(p.getPredmet());
        }
        return list;
    }
    
    public static ArrayList<Predmet> toList(Student z) {
        if (z == null) {
            return null;
        }
        ArrayList<Predmet> list = new ArrayList<Predmet>();
        for (Raspored p : new ArrayList<Raspored>(z.getRasporeds())) {
            list.add(p.getPredmet());
        }
        return list;
    }
}
